package com.crm.mapper;

import com.crm.entity.ClueRecord;
import com.crm.entity.Fake;
import com.crm.entity.Follow;
import org.apache.ibatis.annotations.*;

import java.util.List;

//跟进表操作
@Mapper
public interface FollowMapper {

    /**
     * 查询最大的id
     */
    @Select("select max(id) from follow")
    Long selectMaxId();

    void insertFollow(Follow follow);

    void updateFollow(Follow follow);
    @Select("select * from follow where clueid = #{id}")
    Follow getFollowById(Long id);

    /**
     * 转为商机后删除跟进
     */
    @Delete("delete from follow where clueid = #{id}")
    void deleteFollow(Long id);

    /**
     * 根据线索id查询跟进列表
     */
    List<ClueRecord> selectByClueId(Long clueId);

    /**
     * 查找伪线索表最大id
     */
    @Select("select max(id) from fake")
    Long getMaxIdByFake();

    /**
     * 获取伪线索次数
     */
    @Select("select COUNT(*) from fake where clueid = #{id}")
    Integer countFake(Long id);

    /**
     * 删除线索跟进
     */
    @Delete("delete from follow where clueid = #{id}")
    void deleteClue(Long id);

    /**
     * 删除伪线索信息
     * @param id
     */
    @Delete("delete from fake where clueid = #{id}")
    void deleteFake(Long id);

    /**
     * 添加伪线索信息
     */
    @Insert("insert into fake(id,clueid,falseReason,falsecount,notes) values(#{id},#{clueid},#{falseReason},#{falsecount},#{notes})")
    void insertFake(Fake fake);

    /**
     * 跟新跟进表new01
     */
    @Update("update follow set new01 = 1 where clueid = #{clueid}")
    void updateClueId(Long clueid);

}
